#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<algorithm>
using namespace std;
using ll = long long;
const int N = 100010;
ll a[N], c[N], s[N];
int n, m;
int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        s[i] = s[i - 1] + a[i];
    }
    cin >> m;
    ll sum1 = 0, sum2 = 0;
    while (m--)
    {
        int l, r;
        cin >> l >> r;
        sum1 += s[r] - s[l - 1];
        c[l] += 1, c[r + 1] -= 1;
    }
    for (int i = 1; i <= n; i++)
    {
        s[i] = s[i - 1] + c[i];
    }
    sort(a + 1, a + n + 1);
    sort(s + 1, s + n + 1);
    for (int i = 1; i <= n; i++)
    {
        sum2 += (ll)a[i] * s[i];
    }
    cout << sum2 - sum1 << endl;
    return 0;
}